﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace KeePassLib
{
    public class AlternativeUser : User
    {
        public override bool Equals(object obj)
        {
            if (obj is AlternativeUser)
            {
                return ((AlternativeUser)obj).Username == this.Username && ((AlternativeUser)obj).Password == this.Password;
            }
            return base.Equals(obj);
        }


      /*  public enum Rights
        {
            Read=0,
            ReadWrite=1
        }*/
        public string Username
        {
            get;
            set;
        }

        public string Password
        {
            get;
            set;
        }
     /*   public Rights EditRights
        {
            get;
            private set;
        }*/


        public AlternativeUser(string username, string password)//, Rights rights)
        {
            Username = username;
            Password = password;
          //  EditRights = rights;
        }

        public override bool HasWriteRights(PwGroup group)
        {
            if (group == null) return false;
            return group.WritableUsersContains(this);
        }

        public override bool HasReadRights(PwGroup group)
        {
            if (group == null) return false;
            return group.ReadableUsersContains(this);
        }


        public override bool HasChildNodeWithReadRights(PwGroup group)
        {
            if (group == null) return false;
            if (group.Groups.UCount > 0)
            {
                foreach (PwGroup subGr in group.Groups)
                    if (HasChildNodeWithReadRights(subGr))
                        return true;
                return false;
            }
            else return HasReadRights(group);
        }

        public override bool HasChildNodeWithWriteRights(PwGroup group)
        {
            if (group == null) return false;
            if (group.Groups.UCount > 0)
            {
                foreach (PwGroup subGr in group.Groups)
                    if (HasChildNodeWithWriteRights(subGr))
                        return true;
                return false;
            }
            else return HasWriteRights(group);
            
        }
    }
}
